{% extends "./inc/base.html" %}
{% block style%}
<link rel="stylesheet" href="/static/admin/js/datepicker/bootstrap-datetimepicker.min.css" type="text/css">
{% endblock %}
{% block content %}
    <section class="hbox stretch">
    <section class="vbox">
        <header class="header bg-light dk">

            <p>用户管理</p>
        </header>
        <section class="scrollable wrapper">

            <section class="panel panel-default">
                <header class="panel-heading">
                    用户列表
                    <i data-title="会员展示列表，可查看、新增、注销会员信息" data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""><i class="fa fa-question-circle"></i></i>
                </header>
                <!--<header class="panel-heading clearfix">
                    <ul class="nav nav-tabs pull-left">
                        <li class="{{controller.get('groupid')|default('active', true)}}"><a href="/admin/user/index"> 全部 </a></li>
                        {%for m in usergroup%}
                        {%if [11,12].indexOf(m.groupid)!=-1 %}<li class="{%if controller.get('groupid')==m.groupid%}active{%endif%}"><a href="/admin/user/index/?groupid={{m.groupid}}">{{m.name}}</a>
                        </li>{%endif%}
                        {%endfor%}
                        <li class="{%if controller.get('groupid')==[1,2,4,6,7,8,9].join(' ')%}active{%endif%}"><a href="/admin/user/index/?groupid={{[1,2,4,6,7,8,9].join('+')}}">系统用户</a>
                        </li>

                    </ul>

                </header>-->
                <div class="row wrapper">

                    <div class="col-sm-9 m-b-xs">
                        <div class="">
                            <a href="/admin/user/adduser" class="btn btn-sm btn-info " data-toggle="ajaxModal">
                                添加会员
                            </a>
                            <!--<a class="btn btn-sm btn-info ajax-post confirm" href="/admin/user/userdel" target-form="ids">
                                删除
                            </a>-->
                        </div>
                    </div>
                </div>
                <div class="input-group pull-left search-form">
                    <a >用户姓名&nbsp&nbsp</a><input  type="text" name="real_name"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >电话号码&nbsp&nbsp</a><input  type="text"  name="mobile"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >公司/商户名称&nbsp&nbsp</a><input  type="text" name="gsmc"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                    <a >会员类型&nbsp&nbsp</a>
                    <select class=" input-sm " name="groupid" >
                        <option style='display: none'></option>
                        <option value="11">普通会员</option>
                        <option value="12">核心企业</option>
                    </select>
                    <span class="input-group-btn" >
                            <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/user/index">搜索</button>
                            <button class="btn btn-sm btn-btn-sm" type="button" id="exportCSV" url="/admin/user/export/?modelexp=2"><i class="fa fa-download"></i>导出列表</button>
                        </span>
                </div>
                <div class="table-responsive" style="position: relative;overflow: auto;width: 100%;">
                    <table class="table table-striped b-t b-light" style="table-layout: fixed;">
                        <thead>
                        <tr>
                            <th style="width:20px;"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                            <th style="width:60px;">序号</th>
                            <th style="width:150px;">会员名称</th>
                            <th style="width:150px;">昵称</th>
                            <th style="width:120px;">会员主体</th>
                            <th style="width:250px;">公司/商户名称</th>
                            <th style="width:200px;">身份证号码</th>
                            <th style="width:200px;">纳税人识别号</th>
                            <th style="width:150px;">电话号码</th>
                            <th style="width:100px;">会员类型</th>
                            <th style="width:100px;">员工编号</th>
                            <th style="width:150px;">认证申请时间</th>
                            <th style="width:150px;">认证审核时间</th>
                            <th style="width:100px;">会员信息</th>
                            <th style="width:100px;">会员注销</th>
                            <th style="width:100px;">备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for item in list %}
                        {%set group=item.groupid|get_member_group%}
                        <tr>
                            <td><label class="checkbox m-n i-checks"><input class="ids" type="checkbox" name="ids" value="{%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}{{item.id}}{%endif%}" {%if item.id|in_Array(controller.config('user_administrator'))%}disabled="true"{%endif%}><i></i></label></td>
                            <td>{{loop.index}}</td>
                            <td>{{item.real_name}} </td>
                            <td>{{item.nickname}} </td>
                            <td>{{item.org_type|get_org_type}}</td>
                            <td>{{item.gsmc}} </td>
                            <td>{{item.user_code}}</td>
                            <td>{{item.nsrsbh}}</td>
                            <td>{{item.mobile}}</td>
                            <td>{{item.groupid|get_groupname}}</td>
                            <td>{{item.ygbh}}</td>
                            <td>{%if item.update_time=="0"%}空{%else%}{{item.update_time| moment('YYYY-MM-DD HH:mm:ss')}}{%endif%}</td>
                            <td>{%if item.shenheshijian==null%}空{%else%}{{item.shenheshijian| moment('YYYY-MM-DD HH:mm:ss')}}{%endif%}</td>
                            <td><a href="/admin/user/showuser/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">查看 </a> </td>
                            <!--<td>
                                <a href="/admin/user/edituser/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">编辑</a>
                                {#<a href="/admin/user/recharge/?ids={{item.id}}" class="text-info" data-toggle="ajaxModal">充值</a>#}
                                {%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}
                                <a href="/admin/user/userdel/?ids={{item.id}}" class="confirm ajax-get text-info">删除</a>
                                {%endif%}
                            </td>-->
                            <td><a href="/admin/user/cancel/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">注销</a></td>
                            <td><a href="/admin/order/viewremarks/?id={{item.id}}&model_name={{controller.tactive}}" class="text-info" data-toggle="ajaxModal">查看</a></td>
                        </tr>
                        {% else %}
                        <tr><td colspan="7"><div class="alert alert-warning alert-block">
                            <button data-dismiss="alert" class="close" type="button">×</button>
                            <p>暂无数据</p>
                        </div></td></tr>

                        {% endfor %}


                        </tbody>
                    </table>
                </div>
                <footer class="panel-footer">
                    <div class="row">


                        <div class="col-sm-12 text-right text-center-xs">
                            {{pagerData | safe}}
                        </div>
                    </div>
                </footer>
            </section>
        </section>
    </section>
    </section>
{% endblock%}

{% block script%}
<script src="/static/admin/js/parsley/parsley.min.js"></script>
<script src="/static/admin/js/parsley/parsley.extend.js"></script>
<script src="/static/admin/js/datepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="/static/admin/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<script>
$(function () {

    function isPriceNumber(_keyword){
        if(_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00"){
            _keyword = "0"; return true;
        }else{
            var index = _keyword.indexOf("0");
            var length = _keyword.length;
            if(index == 0 && length>1){/*0开头的数字串*/
                var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }else{/*非0开头的数字*/
                var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }
            return false;
        }
    }
    $(document).on('click', ".recharge", function (e) {
        var balance = $("input[name='balance']").val();
        var name = $("input[name = 'name']").val();
        var id = $("input[name = 'id']").val();
        if(!isPriceNumber(balance)){
            swal( "请填写正确的价格.");
            return false;
        }
        swal({
            title: "确认您的操作！",
            text: "您将给 "+name+" 充值 "+balance+" 元！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定充值!",
            cancelButtonText: "关闭!",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                url:"/admin/user/recharge",
                data:{balance:balance,id:id},
                type:"POST",
                success:function (res) {
                    if(res.errno == 0){
                        swal(res.data.name, "", "success");
                        $('#ajaxModal').modal('hide');
                        location.reload();
                    }

                }
            })

        });
    })
  //搜索功能
  $("#search").click(function(){
    var url = $(this).attr('url');
    var query  = $('.search-form').find('input,select').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
  });

  $("#exportCSV").click(function(){
    var url = $(this).attr('url');
    var query  = $('.search-form').find('input,select').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
    //window.open("/admin/userqx/export")
  });

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });
})
</script>
{% endblock %}
